//logs.js
var util = require('../../utils/util.js')
var app = getApp();
var letCourse;
var openId;
var userId;

Page({
    data: {
        courseList: [],
        indexi:0,
        introduceList:[]
    },

    onLoad: function (option) {
        console.log(option)
        this.setData({
            indexi: option.indexi
        })
        this.getAppletLessonList(); 
        
    },
    goPage: function (e) {
        let that = this;
        console.log(e);
        wx.setStorageSync('indexI', e.currentTarget.dataset.mark)
        let url = e.currentTarget.dataset.url;
        let ispublic = e.currentTarget.dataset.ispublic;
        
        letCourse = wx.getStorageSync('letCourse').course;
        
        let isLetPay = letCourse.isLetPay;
        // 跳转
        if (ispublic == 1 || isLetPay) {
             wx.setStorageSync('qiehuan', 0) //切换页面相关
            wx.switchTab({
                url: url
            })
        } else {
            // 提示
            wx.showToast({
                title: '请先购买该课程',
                icon: 'none',
                duration: 2000
            })
        }

    },
    // 获取课程的节数内容
    getAppletLessonList: function () {
        let that = this;
        openId = wx.getStorageSync('openId');
        userId = wx.getStorageSync('userId');
        letCourse = wx.getStorageSync('letCourse').course;;
        // wx.setNavigationBarTitle({
        //     title: letCourse.name
        // })
        wx.request({
            url: app.globalData.url + "/getAppletLessonList",
            data: {
                openId: openId,
                userId: userId,
                productId: letCourse.productId

            },
            success: function (res) {
                console.log(res);
                let cl = res.data.Lesson.result;
                for (var i = 0, count = cl.length; i < count; i++) {
                    cl[i].duration = util.shijian(cl[i].duration)
                }
                that.setData({
                    courseList: res.data.Lesson.result,
                    introduceList: letCourse
                   
                })
            }
        })
    },
})
